
var ValidateRule = $createClass('ValidateRule',
	function(option){
		if(!option){
			option = {};
		}
		if(option.msg){
			this.msg = option.msg;
		}
	});
/**
 * 返回
 */
ValidateRule.prototype.getMsg=function(obj){
	var msg = "&nbsp;";
	
	if(this.msg && obj){
		var name = obj.getName();
		if(!name) name="";
		msg = this.msg.replace("_name_",name);
		msg='<span style="color:#ff0000">'+msg+ '</span>';
	}
	return msg;
}


/**
 * @description 判断是否为空 
 * @constructor CheckEmpty
 * @param	option JSON对象 
 * @example	new CheckEmpty({msg:'此项不能为空'}); 
 */
var CheckEmpty = $createClass('CheckEmpty',function(option){
	this.msg = "_name_不能为空！";
	this.ValidateRule(option);
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckEmpty.prototype.validate = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1) {
		throw  this.getMsg(obj);    
	}
}





/**
 * @description 验证最大长度
 * @constructor CheckMaxLength
 * @param	option JSON对象 
 * @example	new CheckMaxLength({msg:'最大长度不可超过16位',length:'16'}); 
 */
var CheckMaxLength =  $createClass('CheckMaxLength',function(option){
	this.msg = "_name_不能大于_length_！";
	this.ValidateRule(option);
	
	if(option && option.length)
		this.length = option.length;
	this.preGetMsg = this.getMsg;
	
	this.getMsg = function(obj){
		var msg = this.preGetMsg(obj);
		msg = msg.replace("_length_",this.length)
		return msg;
	}
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckMaxLength.prototype.validate = function(obj){
	if(obj.getValue().replace){
		var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
		var getLength = value.replace(/[^\x00-\xff]/g, "**").length;
		if (getLength<1)  return true;
		if(getLength>this.length){		
			 throw  this.getMsg(obj);     
		}
	}
}




/**
 * @description 验证长度区间
 * @constructor CheckLength
 * @param	option JSON对象 
 * @example	new CheckLength({msg:'长度区间是6－16位',maxLength:'16',minLength:'6'}); 
 */
var CheckLength=  $createClass('CheckLength',function(option){
	
	this.ValidateRule(option);
	if(option ){
		this.maxLength = option.maxLength;
	    this.minLength = 0;
	    if(option.minLength)
			this.minLength = option.minLength;
	}
	if(!this.msg ){
		this.msg = "_name_不能为空！";
	}
	this.preGetMsg = this.getMsg;
	this.getMsg = function(obj){
		var msg = this.preGetMsg(obj);
		msg = msg.replace("_minLength_",this.maxLength)
		msg = msg.replace("_maxLength_",this.maxLength)
		return msg;
	}
},'ValidateRule');
  	
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckLength.prototype.validate  = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	var len = value.replace(/[^\x00-\xff]/g, "**").length;
	if(this.maxLength<len||len<this.minLength){
    	 throw  this.getMsg(obj);       
	}
}





/**
 * @description 验证非法字符
 * @constructor CheckValidString
 * @param	option JSON对象 
 * @example	new CheckValidString({msg:'您的输入项中包含了非法字符，请修正'}); 
 */
var CheckValidString=$createClass('CheckValidString',function(option){
	this.msg = "_name_必须是字母和数字的组合！";
	this.ValidateRule(option);
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckValidString.prototype.validate= function(obj){
	 var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	 var s=value;
	 if (s.length<1)  return true;
	 var i,j,strTemp;
	 strTemp="%#_&<>=\"?'\\";
	 for (i=0;i<s.length;i++) {
		 j = strTemp.indexOf(s.charAt(i));
		 if (j>=0) {
		 	 throw  this.getMsg(obj);   
		 }
	}
}





/**
 * @description 验证只能输入整数
 * @constructor CheckIsInt
 * @param	option JSON对象 
 * @example	new CheckIsInt({msg:'请输入整数'}); 
 */
var CheckIsInt=$createClass('CheckIsInt',function(option){
	this.msg = "_name_必须是整型！";
	this.ValidateRule(option);
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckIsInt.prototype.validate = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var num = value;
	var patrn=/^-?\d+$/;
	if (!patrn.exec(num)){
		throw  this.getMsg(obj);  
	} 
}

/**
 * @description 验证只能输入自然数(0,1,2,3...)
 * @constructor CheckNaturalInt
 * @param	option JSON对象 
 * @example	new CheckNaturalInt({msg:'请输入大于等于0的整数'}); 
 */
var CheckNaturalInt=$createClass('CheckNaturalInt',function(option){
	this.msg = "_name_必须是自然数！";
	this.ValidateRule(option);
},'ValidateRule');

CheckNaturalInt.prototype.validate = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var num = value;
	var patrn=/^\d+$/;
	if (!patrn.exec(num)){
		throw  this.getMsg(obj);  
	} 
}




/**
 * @description 验证是否是一个正整数
 * @constructor CheckPlusInt
 * @param	option JSON对象 
 * @example	new CheckPlusInt({msg:'请输入正整数'}); 
 */
var CheckPlusInt=$createClass('CheckPlusInt',function(option){
	this.msg = "_name_必须是正整数！";
	this.ValidateRule(option);
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckPlusInt.prototype.validate= function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var num = value;
	var patrn=/^[0-9]*[1-9][0-9]*$/;
	if (!patrn.exec(num)){
		throw  this.getMsg(obj);  
	} 
}

/**
 * @description 验证区号
 * @constructor CheckQh
 * @param	option JSON对象 
 * @example	new CheckQh({msg:'请输入正确的区号'}); 
 */
var CheckQh=$createClass('CheckQh',function(option){
	this.msg = "_name_不是合法的区号！";
	this.ValidateRule(option);
},'ValidateRule');
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckQh.prototype.validate= function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var patrn=/^0(10|2\d|(3|4|5|6|7|8|9)\d{2})$/;
	if(!patrn.exec(value)){	
		throw  this.getMsg();  
	}
}





/**
 * @description 验证电话号码（不带区号）
 * @constructor CheckQh
 * @param	option JSON对象 
 * @example	new CheckQh({msg:'请输入正确的电话号码'}); 
 */
var CheckDhhm=$createClass('CheckDhhm',function(option){
	this.msg = "_name_必须是合法的电话号码！";
	this.ValidateRule(option);
},'ValidateRule')
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckDhhm.prototype.validate = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var patrn=/^\s*\d{7,8}\s*$/;
	if(!patrn.exec(value)){	
		throw  this.getMsg(obj); 
	}
}





/**
 * @description 验证邮政编码
 * @constructor CheckPostalCode
 * @param	option JSON对象 
 * @example	new CheckPostalCode({msg:'请输入正确的邮政编码'}); 
 */
var CheckPostalCode=$createClass('CheckPostalCode',function(option){
	this.msg = "_name_必须是合法的邮政编码！";
	this.ValidateRule(option);
},'ValidateRule')
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckPostalCode.prototype.validate = function(obj){
	var value = obj.getValue().replace(/(^\s*)|(\s*$)/g, "");
	if (value.length<1)  return true;
	var patrn=/^[1-9]{1}(\d+){5}$/;
	if(!patrn.exec(value)){	
		throw  this.getMsg(obj); 
	}
}





/**
 * @description 验证手机号码
 * @constructor CheckMobile
 * @param	option JSON对象 
 * @example	new CheckMobile({msg:'请输入正确的手机号码'}); 
 */
var CheckMobile=$createClass('CheckMobile',function(option){
	this.msg = "_name_必须是合法的手机号码！";
	this.ValidateRule(option);
},'ValidateRule')
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws msg 错误提示信息
 */
CheckMobile.prototype.validate= function(obj){
	if (obj.getValue().length<1)  return true;
	var patrn=/^\s*(\+86)*0*1(3|5|8)\d{9}\s*$/;
	if(!patrn.exec(obj.getValue())){	
		throw  this.getMsg();	
	}			 
}





/**
 * @description 验证EMAIL
 * @constructor CheckEmail
 * @param	option JSON对象 
 * @example	new CheckEmail({msg:'请输入正确的EMAIL'}); 
 */
var CheckEmail=$createClass('CheckEmail',function(option){
	this.msg = "_name_必须是合法的email！";
	this.ValidateRule(option);
},'ValidateRule')
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws  msg 错误提示信息
 */
CheckEmail.prototype.validate= function(obj){
	if (obj.getValue().length<1)  return true;
	var patrn = /^\s*[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+\s*$/;
	if(!patrn.exec(obj.getValue())){	
		throw this.getMsg(obj);	
	}		
}


/**
 * @description 验证EMAIL
 * @constructor CheckEmail
 * @param	option JSON对象 
 * @example	new CheckEmail({msg:'请输入正确的EMAIL'}); 
 */
var CheckNotChinese=$createClass('CheckNotChinese',function(option){
	this.msg = "_name_不能包含中文！";
	this.ValidateRule(option);
},'ValidateRule')
/**
 * @description 执行校验
 * @param	obj  校验对象
 * @throws  msg 错误提示信息
 */
CheckNotChinese.prototype.validate= function(obj){
	if (obj.getValue().length<1)  return true;
	var patrn =/^[\u4e00-\u9fa5]+$/;
	if(patrn.exec(obj.getValue())){	
		throw this.getMsg(obj);	
	}		
}

//匹配正整数或两位小数
var CheckTwoDecimal =$createClass('CheckTwoDecimal',function(option){
	this.msg = "_name_只能输入正整数或两位小数";
	this.ValidateRule(option);
},'ValidateRule')

CheckTwoDecimal.prototype.validate= function(obj){
	if (obj.getValue().length<1)  return true;
	var patrn = /^\d+(\.\d{1,2})?$/;
	if(!patrn.exec(obj.getValue())){	
		throw this.getMsg(obj);	
	}		
}

